package com.gpframework.module.order.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.annotation.Excel;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.order.domain.GpOrder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @ClassName GpOrderReq
 * @Author gpframework
 * @Date 2023-06-16
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpOrderReq extends BaseReq {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty("id")
    private Long id;
         @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("订单特性(大货/散剪)")
     private String orderCharacteristics;
     @ApiModelProperty("订单状态")
     private String orderStatus;
     @ApiModelProperty("订单二维码")
     private String orderQrCode;
     @ApiModelProperty("流入时间")
     private Date flowInTime;
     @ApiModelProperty("订单时长")
     private Long orderDuration;
     @ApiModelProperty("工作量")
     private BigDecimal workload;
     @ApiModelProperty("超期时长")
     private Long overdueDuration;
     @ApiModelProperty("是否打印二维码")
     private Integer isPrintQrCode;
     @ApiModelProperty("是否异常")
     private Integer isException;
     @ApiModelProperty("是否加急")
     private Integer isUrgent;
     @ApiModelProperty("是否作废")
     private Integer isCancel;
     @ApiModelProperty("是否暂停")
     private Integer isSuspend;
     @ApiModelProperty("是否验货")
     private Integer isInspection;
     @ApiModelProperty("操作备注")
     private String operationRemark;
     @ApiModelProperty("表单名称")
     private String formName;
     @ApiModelProperty("档口")
     private String organiseUnit;
     @ApiModelProperty("表单类型")
     private Long formType;
     @ApiModelProperty("客户名称")
     private String clientName;
     @ApiModelProperty("订单编号")
     private String formCode;
     @ApiModelProperty("预期付款金额")
     private String expectPayment;
     @ApiModelProperty("总分支数量")
     private String totalBranchesQuantity;
     @ApiModelProperty("总数量")
     private String totalQuantity;
     @ApiModelProperty("总邮寄数量")
     private String totalPostQuantity;
     @ApiModelProperty("运费")
     private String freight;
     @ApiModelProperty("备注")
     private String remark;
     @ApiModelProperty("联系人及电话")
     private String linkManAndPhone;
     @ApiModelProperty("地址")
     private String address;
     @ApiModelProperty("销售员")
     private String salesman;
     @ApiModelProperty("是否有效")
     private Integer isValid;
     @ApiModelProperty("是否显示批次号")
     private Integer isShowBatchNo;
     @ApiModelProperty("是否显示运费")
     private Integer isShowFreight;
     @ApiModelProperty("是否显示备注")
     private Integer isShowRemark;
     @ApiModelProperty("是否显示联系人及电话")
     private Integer isShowLinkManAndPhone;
     @ApiModelProperty("是否显示地址")
     private Integer isShowAddress;
     @ApiModelProperty("是否显示邮寄数量")
     private Integer isShowPostQuantity;
     @ApiModelProperty("是否显示价格")
     private Integer isShowPrice;
     @ApiModelProperty("调整金额")
     private String adjustAmount;
     @ApiModelProperty("预付金额")
     private String advanceAmount;
     @ApiModelProperty("收款金额")
     private String collectingAmount;
     @ApiModelProperty("已收/已付")
     private String paidInOrOut;
     @ApiModelProperty("订单余额")
     private String orderBalance;
     @ApiModelProperty("订单云编号")
     private String orderCloudNumber;
     @ApiModelProperty("查询条件（订单号/客户名）")
     private String searchName;
     @ApiModelProperty("查询条件（车次）")
     private String destinationNo;
     @ApiModelProperty("用户id")
     private Long userId;
     @ApiModelProperty("部门id")
     private Long deptIds;
     @ApiModelProperty("创建人")
     private String createBy;
     @ApiModelProperty("创建开始时间")
     private Date createStartTime;
     @ApiModelProperty("创建结束时间")
     private Date createEndTime;
     @ApiModelProperty("查询日期")
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date searchDate;
    @ApiModelProperty("查询日期类型： 1当天 2历史")
    private String searchDateType;
    @ApiModelProperty("是否按录入时间排序")
    private Integer orderByCreateTime;
    @ApiModelProperty("流转类型")
    private String type;
    @ApiModelProperty("查询图片类型： 1细码 2物流单 3自提")
    private String flowStatus;
    @ApiModelProperty("是否按转发状态排序")
    private String orderByForward;
    @ApiModelProperty("查询条件（订单号/客户名/品名）")
    private String productName;
    @ApiModelProperty("操作人id")
    private Long operatorId;
    @ApiModelProperty("是否已超时（0：否；1：是）")
    private String isTimeout;
    private QueryWrapper<GpOrder> ew;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpOrder> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (StringUtils.isNotBlank(this.getOrderCharacteristics())){
        lqw.eq(alias+"order_characteristics" ,this.getOrderCharacteristics());
        }
        if (StringUtils.isNotBlank(this.getOrderStatus())){
            lqw.apply("find_in_set(gp.order_status,'" + this.getOrderStatus() + "')");
        }
        if (StringUtils.isNotBlank(this.getOrderQrCode())){
        lqw.eq(alias+"order_qr_code" ,this.getOrderQrCode());
        }
        if (this.getFlowInTime() != null){
        lqw.eq(alias+"flow_in_time" ,this.getFlowInTime());
        }
        if (this.getOrderDuration() != null){
        lqw.eq(alias+"order_duration" ,this.getOrderDuration());
        }
        if (this.getWorkload() != null){
        lqw.eq(alias+"workload" ,this.getWorkload());
        }
        if (this.getOverdueDuration() != null){
        lqw.eq(alias+"overdue_duration" ,this.getOverdueDuration());
        }
        if (this.getIsPrintQrCode() != null){
        lqw.eq(alias+"is_print_qr_code" ,this.getIsPrintQrCode());
        }
        if (this.getIsException() != null){
        lqw.eq(alias+"is_exception" ,this.getIsException());
        }
        if (this.getIsUrgent() != null){
        lqw.eq(alias+"is_urgent" ,this.getIsUrgent());
        }
        if (this.getIsCancel() != null){
        lqw.eq(alias+"is_cancel" ,this.getIsCancel());
        }
        if (this.getIsSuspend() != null){
        lqw.eq(alias+"is_suspend" ,this.getIsSuspend());
        }
        if (this.getIsInspection() != null){
        lqw.eq(alias+"is_inspection" ,this.getIsInspection());
        }
        if (StringUtils.isNotBlank(this.getOperationRemark())){
        lqw.eq(alias+"operation_remark" ,this.getOperationRemark());
        }
        if (StringUtils.isNotBlank(this.getFormName())){
            lqw.like(alias+"form_name",this.getFormName());
        }
        if (StringUtils.isNotBlank(this.getOrganiseUnit())){
        lqw.like(alias+"organise_unit" ,this.getOrganiseUnit());
        }
        if (this.getFormType() != null){
        lqw.eq(alias+"form_type" ,this.getFormType());
        }
        if (StringUtils.isNotBlank(this.getClientName())){
            lqw.like(alias+"client_name",this.getClientName());
        }
        if (StringUtils.isNotBlank(this.getFormCode())){
        lqw.like(alias+"form_code" ,this.getFormCode());
        }
        if (StringUtils.isNotBlank(this.getExpectPayment())){
        lqw.eq(alias+"expect_payment" ,this.getExpectPayment());
        }
        if (StringUtils.isNotBlank(this.getTotalBranchesQuantity())){
        lqw.eq(alias+"total_branches_quantity" ,this.getTotalBranchesQuantity());
        }
        if (StringUtils.isNotBlank(this.getTotalQuantity())){
        lqw.eq(alias+"total_quantity" ,this.getTotalQuantity());
        }
        if (StringUtils.isNotBlank(this.getTotalPostQuantity())){
        lqw.eq(alias+"total_post_quantity" ,this.getTotalPostQuantity());
        }
        if (StringUtils.isNotBlank(this.getFreight())){
        lqw.eq(alias+"freight" ,this.getFreight());
        }
        if (StringUtils.isNotBlank(this.getRemark())){
        lqw.eq(alias+"remark" ,this.getRemark());
        }
        if (StringUtils.isNotBlank(this.getLinkManAndPhone())){
        lqw.like(alias+"link_man_and_phone" ,this.getLinkManAndPhone());
        }
        if (StringUtils.isNotBlank(this.getAddress())){
        lqw.eq(alias+"address" ,this.getAddress());
        }
        if (this.getIsValid() != null){
        lqw.eq(alias+"is_valid" ,this.getIsValid());
        }
        if (this.getIsShowBatchNo() != null){
        lqw.eq(alias+"is_show_batch_no" ,this.getIsShowBatchNo());
        }
        if (this.getIsShowFreight() != null){
        lqw.eq(alias+"is_show_freight" ,this.getIsShowFreight());
        }
        if (this.getIsShowRemark() != null){
        lqw.eq(alias+"is_show_remark" ,this.getIsShowRemark());
        }
        if (this.getIsShowLinkManAndPhone() != null){
        lqw.eq(alias+"is_show_link_man_and_phone" ,this.getIsShowLinkManAndPhone());
        }
        if (this.getIsShowAddress() != null){
        lqw.eq(alias+"is_show_address" ,this.getIsShowAddress());
        }
        if (this.getIsShowPostQuantity() != null){
        lqw.eq(alias+"is_show_post_quantity" ,this.getIsShowPostQuantity());
        }
        if (this.getIsShowPrice() != null){
        lqw.eq(alias+"is_show_price" ,this.getIsShowPrice());
        }
        if (StringUtils.isNotBlank(this.getAdjustAmount())){
        lqw.eq(alias+"adjust_amount" ,this.getAdjustAmount());
        }
        if (StringUtils.isNotBlank(this.getAdvanceAmount())){
        lqw.eq(alias+"advance_amount" ,this.getAdvanceAmount());
        }
        if (StringUtils.isNotBlank(this.getCollectingAmount())){
        lqw.eq(alias+"collecting_amount" ,this.getCollectingAmount());
        }
        if (StringUtils.isNotBlank(this.getPaidInOrOut())){
        lqw.eq(alias+"paid_in_or_out" ,this.getPaidInOrOut());
        }
        if (StringUtils.isNotBlank(this.getOrderBalance())){
        lqw.eq(alias+"order_balance" ,this.getOrderBalance());
        }
        if (StringUtils.isNotBlank(this.getOrderCloudNumber())){
        lqw.eq(alias+"order_cloud_number" ,this.getOrderCloudNumber());
        }
        if (StringUtils.isNotBlank(this.getSearchName())){
        lqw.and(wrapper -> wrapper.like("gp.form_code", this.getSearchName()).or().like("gp.client_name", this.getSearchName()));
        }
        if (StringUtils.isNotBlank(this.getDestinationNo())){
        lqw.eq("gof.destination_no", this.getDestinationNo());
        }
        if (StringUtils.isNotBlank(this.getCreateBy())){
            lqw.eq(alias+"create_by" ,this.getCreateBy());
        }
        if (this.getCreateStartTime() != null && this.getCreateEndTime() != null){
            lqw.between(alias+"create_time", this.getCreateStartTime(), this.getCreateEndTime());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.and(wrapper -> wrapper.like("gp.form_code", this.getProductName())
                    .or().like("gp.client_name", this.getProductName())
                    .or().like("p.product_name", this.getProductName())
                    .or().like("gp.remark", this.getProductName()));
        }
    }
}
